<template>
	<section>
		<el-col :span="24" class="toolbar"  style="padding-bottom: 0px;">
			<el-form :inline="true">
				<el-form-item>
					<el-button type="primary" v-if="$store.state.role!='manager'" @click="handleAdd">添加课程章节</el-button>
				</el-form-item>				
				<el-form-item>
					<el-input v-model="key"  placeholder="输入查询的关键字"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="getList">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>			
		<!--列表-->
		<el-tabs v-model="tabletype"  type="card">
		    <el-tab-pane label="我的课程章节" name='0'></el-tab-pane>
		    <el-tab-pane label="共享课程章节" name='1'></el-tab-pane>
		    <el-tab-pane label="内置课程章节" name='2'></el-tab-pane>
		</el-tabs>	
		<!--工具条-->		
		<el-table :data="Lists" highlight-current-row v-loading="loading" style="width: 100%;" @sort-change="sortChange">
			<el-table-column  type="index"   width='80'>
			</el-table-column>
			<el-table-column prop="name" label="课程章节名称"width="200">
			</el-table-column>
			<el-table-column prop="courseStage" label="课程章节类型"width="200">
				<template scope="scope">
					<p>{{scope.row.courseStage=='0'?'创业基础小节':'案例分析小节'}}</p>
				</template>				
			</el-table-column>
			<el-table-column prop="businessModelName" label="商业模式板块"width="200">
			</el-table-column>			
			<el-table-column prop="realName" label="创建人" width="200" >
			</el-table-column>
			<el-table-column prop="orgName" label="所属单位" width="200">
			</el-table-column>			
			<el-table-column prop="createTime" label="添加时间" width="200">
			</el-table-column>
			<el-table-column prop="referenceCount" label="引用次数" width="200">
			</el-table-column>			
			<el-table-column prop="birth" min-width="300" label="操作" fixed="right" >
				<template scope="scope">
					<el-button size="small"  v-if="tabletype=='0'||$store.state.role=='admin'" type="danger" @click="handleDel(scope.row)">删除</el-button>
					<el-button size="small"  v-if="tabletype=='0'&&$store.state.role!='manager'||$store.state.role=='admin'" type="primary" @click="getone(scope.row,'edit')">编辑</el-button>
					<el-button size="small" type="success" @click="Lookone(scope.row,'look')">预览</el-button>
					<el-button size="small" type="warning" v-if="scope.row.isShared==false&&tabletype!=2&&$store.state.role!='admin'&&$store.state.role!='manager'" @click="goShared(scope.row,1)">共享</el-button>
					<el-button size="small" type="info" v-if="scope.row.isShared&&tabletype=='0'&&$store.state.role!='admin'" @click="goShared(scope.row,0)">取消共享</el-button>
				</template>					
			</el-table-column>
		</el-table>
		<!--工具-->
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;">
			</el-pagination>
		</el-col>		
		<!--新增界面-->
		<el-dialog  title="添加课程章节" :fullscreen="false" custom-class="templetdialog" width="30%"  v-model="addFormVisible" :close-on-click-modal="false">
			<el-form :model="addtemplet" status-icon class="demo-ruleForm" :rules="addtempletrule" ref="addtemplet" label-width="50px">		
				<el-form-item label="课程章节名称"  label-width="80"  prop="name"> 
				    <el-input style="width:40%;" type="text" placeholder="填写小节名称（15字以内）"  v-model="addtemplet.name"></el-input>
				</el-form-item>	
				<el-form-item label="课程章节类型" label-width="80" prop="courseStage">
				    <el-radio-group v-model="addtemplet.courseStage">
				      <el-radio label="0">创业基础课程章节</el-radio>
				      <el-radio label="1">案例分析课程章节</el-radio>
				    </el-radio-group>
				</el-form-item>	
				<el-form-item label="所属商业模式版块" label-width="80"  prop="businessModelId" v-if="addtemplet.courseStage==0">
				    <el-select placeholder="请选择版块"  v-model="addtemplet.businessModelId">
				      <el-option v-for="el in bussinessList" :value="el.businessModelId" :label="el.name"></el-option>
				    </el-select>
				</el-form-item>				
				<el-form-item label="教案选择"  label-width="80" >
					<el-row>
						<el-col :span="10">
						    <el-select placeholder="请选择教案" style="width: 100%;" v-model="addtemplet.planIds" multiple >
						      <el-option v-for="el in planlist" :value="el.planId" :label="el.name" :key="el.planId"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="10" :offset="1">
						  <el-radio-group v-model="planselect">
						    <el-radio-button label="1">只看自己</el-radio-button>
						    <el-radio-button label="2">共享教案</el-radio-button>
						    <el-radio-button label="3">内置教案</el-radio-button>
						  </el-radio-group>							
						</el-col>						
					</el-row>

				</el-form-item>				
				<el-form-item label="视频选择" label-width="80">
					<el-row>
						<el-col :span="10">
						    <el-select placeholder="请选择视频" style="width: 100%;" v-model="addtemplet.videoIds" multiple >
						      <el-option v-for="el in videolist" :value="el.videoId" :label="el.name" :key="el.videoId"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="10" :offset="1">
							<el-radio-group v-model="videoselect">
							    <el-radio-button label="1">只看自己</el-radio-button>
							    <el-radio-button label="2">共享视频</el-radio-button>
							    <el-radio-button label="3">内置视频</el-radio-button>
							</el-radio-group>							
						</el-col>							
					</el-row>
				</el-form-item>		
				<el-form-item label="图纸选择" label-width="80" v-if="addtemplet.courseStage==1" >
					<el-row>
						<el-col :span="10">
						    <el-select placeholder="请选择图纸" style="width: 100%;" v-model="addtemplet.drawingIds" multiple >
						      <el-option v-for="el in drawlist" :value="el.drawingId" :label="el.name" :key="el.drawingId"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="10" :offset="1">
							<el-radio-group v-model="drawselect">
							    <el-radio-button label="1">只看自己</el-radio-button>
							    <el-radio-button label="2">共享图纸</el-radio-button>
							    <el-radio-button label="3">内置图纸</el-radio-button>
							</el-radio-group>							
						</el-col>							
					</el-row>
				</el-form-item>		
				<el-form-item label="试题选择" label-width="80"  prop="problemIds">
					<el-row>
						<el-col  :span="10">
						    <el-select placeholder="请选择作业" style="width: 100%;" v-model="addtemplet.problemIds" multiple >
						      <el-option v-for="el in worklist" :value="el.problemId" :label="el.name" :key="el.problemId"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="10" :offset="1">
							<el-radio-group v-model="workselect">
							    <el-radio-button label="1">只看自己</el-radio-button>
							    <el-radio-button label="2">共享作业</el-radio-button>
							    <el-radio-button label="3">内置作业</el-radio-button>
							</el-radio-group>							
						</el-col>
					</el-row>
				</el-form-item>							
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="addFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
			</div>
		</el-dialog>
		<!--编辑界面-->
		<el-dialog  title="编辑课程章节" :fullscreen="false" custom-class="templetdialog" width="30%"  v-model="editFormVisible" :close-on-click-modal="false">
			<el-form :model="edittemplet" status-icon class="demo-ruleForm" :rules="edittempletrule" ref="edittemplet" label-width="50px">		
				<el-form-item label="课程章节名称"  label-width="80"  prop="name"> 
				    <el-input style="width:40%;" type="text"  placeholder="填写小节名称（15字以内）"  v-model="edittemplet.name"></el-input>
				</el-form-item>	
				<el-form-item label="课程章节类型" label-width="80" prop="courseStage" >
				    <el-radio-group v-model="edittemplet.courseStage" disabled>
				      <el-radio label="0">创业基础课程章节</el-radio>
				      <el-radio label="1">案例分析课程章节</el-radio>
				    </el-radio-group>
				</el-form-item>	
				<el-form-item label="所属商业模式版块" label-width="80"  prop="businessModelId" v-if="edittemplet.courseStage==0">
				    <el-select placeholder="请选择版块"  v-model="edittemplet.businessModelId" v-on:change="Businessmodel">
				      <el-option v-for="el in bussinessList" :value="el.businessModelId" :label="el.name" ></el-option>
				    </el-select>
				</el-form-item>				
				<el-form-item label="教案选择"  label-width="80" >
					<el-row>
						<el-col :span="10">
						    <el-select placeholder="请选择教案选择" style="width: 100%;" v-model="edittemplet.planIds" multiple >
						      <el-option v-for="el in planlist" :value="el.planId" :label="el.name" :key="el.planId"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="10" :offset="1">
						  <el-radio-group v-model="planselect">
						    <el-radio-button label="1">只看自己</el-radio-button>
						    <el-radio-button label="2">共享教案</el-radio-button>
						    <el-radio-button label="3">内置教案</el-radio-button>
						  </el-radio-group>							
						</el-col>						
					</el-row>

				</el-form-item>				
				<el-form-item label="视频选择" label-width="80">
					<el-row>
						<el-col :span="10">
						    <el-select placeholder="请选择视频" style="width: 100%;" v-model="edittemplet.videoIds" multiple >
						      <el-option v-for="el in videolist" :key="el.videoId" :value="el.videoId" :label="el.name"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="10" :offset="1">
							<el-radio-group v-model="videoselect">
							    <el-radio-button label="1">只看自己</el-radio-button>
							    <el-radio-button label="2">共享视频</el-radio-button>
							    <el-radio-button label="3">内置视频</el-radio-button>
							</el-radio-group>							
						</el-col>							
					</el-row>
				</el-form-item>		
				<el-form-item label="图纸选择" label-width="80" v-if="edittemplet.courseStage==1" >
					<el-row>
						<el-col :span="10">
						    <el-select placeholder="请选择图纸" style="width: 100%;" v-model="edittemplet.drawingIds" multiple >
						      <el-option v-for="el in drawlist" :value="el.drawingId" :key="el.drawingId" :label="el.name"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="10" :offset="1">
							<el-radio-group v-model="drawselect">
							    <el-radio-button label="1">只看自己</el-radio-button>
							    <el-radio-button label="2">共享图纸</el-radio-button>
							    <el-radio-button label="3">内置图纸</el-radio-button>
							</el-radio-group>							
						</el-col>							
					</el-row>
				</el-form-item>		
				<el-form-item label="试题选择" label-width="80"   prop="problemIds">
					<el-row>
						<el-col  :span="10">
						    <el-select placeholder="请选择作业" style="width: 100%;" v-model="edittemplet.problemIds" multiple >
						      <el-option v-for="el in worklist" :value="el.problemId" :key="el.problemId" :label="el.name"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="10" :offset="1">
							<el-radio-group v-model="workselect">
							    <el-radio-button label="1">只看自己</el-radio-button>
							    <el-radio-button label="2">共享作业</el-radio-button>
							    <el-radio-button label="3">内置作业</el-radio-button>
							</el-radio-group>							
						</el-col>
					</el-row>
				</el-form-item>							
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="editLoading">更新</el-button>
			</div>
		</el-dialog>	
		<!--查看界面-->
		<el-dialog  title="查看课程章节" :fullscreen="false" custom-class="lookdialog" width="30%"  v-model="lookVisible" :close-on-click-modal="false">
			<template>
				<previews :tochild="looktemplet"  ref="dianss"></previews>
			</template>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="lookVisible = false">关闭</el-button>
			</div>
		</el-dialog>			
	</section>
</template>
<script>
	import {videolistbuil,worklistbuil,drawlistbuil,planlistbuil, templetlist,templetdelete,templetadd,templetone,templetedit,bussinesslist,templetlistbuil,templetnamerule,videolist,worklist,drawlist,planlist} from '../../api/api';
	import preview from '../draw/previewstage.vue';
	export default {	
		data() {
			var rulesname=(rules,value,callback)=>{
				let params={name:this.addtemplet.name};
				templetnamerule(params).then((r)=>{
					if(!r){
						callback(new Error('作业名称重复'))
					}else{
						callback()
					}
				})
			}	
			var problems=(rules,value,callback)=>{
				if(value.length==0){
					callback(new Error('试题选择不能为空'))
				}else{
					callback()
				}
			}				
			var editrulesname=(rules,value,callback)=>{
				if(this.edittemplet.checkname!=this.edittemplet.name){			
					let params={name:this.edittemplet.name};
					templetnamerule(params).then((r)=>{
						if(!r){
							callback(new Error('作业名称重复'))
						}else{
							callback()
						}
					})
				}else{
					callback()
				}
			}				
			let numberrule=(rule, value, callback)=>{
			  if (value < 0 || value > 10) {
			    callback(new Error('分值必须在 0 至 10之间'))
			  } else {
			    callback()
			  }							
			}
			let namelengthrule=(rule, value, callback)=>{
			  if (value.length > 15) {
			    callback(new Error('限制字数15字以内'))
			  } else {
			    callback()
			  }							
			}			
			return {
				planselect:"0",
				videoselect:"0",
				drawselect:"0",
				workselect:"0",
				planisShared:"0",				
				videoisShared:"0",	
				drawisShared:"0",	
				workisShared:"0",	
				planisSelf:"1",
				videoisSelf:"1",
				drawisSelf:"1",
				workisSelf:"1",
				Type:"",
				addFormVisible: false,
				addLoading: false,	
				autotemplet:false,
				editFormVisible: false,
				editLoading: false,						
				loading: true,
				lookVisible:false,
				templetupload:"templet",
				Lists:[],
				fileList:[],
				checkbox:[],
				editfileList:[],	
				bussinessList:[],
				addtemplet:{
					name:"",
					type:"",
					courseStage:"0",
					businessModelId:"",
					planIds:[],
					problemIds:[],
					videoIds:[],
					drawingIds:[],
				},
				edittemplet:{
					planIds:[],
					problemIds:[],
					videoIds:[],
					drawingIds:[],
				},	
				looktemplet:{
					
				},
				addtempletrule: {
					name: [
						{ required: true, message: '请填写课程章节名称', trigger: 'blur' },
						{validator:rulesname,trigger: 'blur'},
					],
					courseStage:[
						{ required: true, message: '请选择课程章节类别', trigger: 'blur' }
					],
					problemIds:[
						{validator:problems,trigger: 'blur'}
					],
					score:[
						{required: true, validator:numberrule, trigger: 'blur'}
					],
					businessModelId:[
						{ required: true, message: '请选择所属商业模式版块', trigger: 'blur' }
					]					
				},	
				edittempletrule: {
					name: [
						{ required: true, message: '请填写课程章节名称', trigger: 'blur' },
						{validator:editrulesname,trigger: 'blur'},
						{validator:namelengthrule,trigger: 'blur'}
						
					],
					courseStage:[
						{ required: true, message: '请选择课程章节类别', trigger: 'blur' }
					],
					problemIds:[
						{validator:problems,trigger: 'blur'}
					],					
					score:[
						{required: true, validator:numberrule, trigger: 'blur'}
					],
					businessModelId:[
						{ required: true, message: '请选择所属商业模式版块', trigger: 'blur' }
					]	
				},
				param:"",
				eidtparam:"",	
				page:"1",
				pagesize:"10",
				total:'',
				key:"",
				isShared:"",
				isSelf:"1",
				videolist:[],
				worklist:[],
				drawlist:[],
				planlist:[],
				templettype:"",
				tabletype:'0',
				sign:'1',
			}
		},
        components:{'previews':preview},		
		watch:{
			'tabletype':function(){
				this.pageNum='1';
				if(this.tabletype==0){
					this.isShared='';
					this.sign=1;
				}
				if(this.tabletype==1){
					this.isShared=1;
					this.sign=2;
				}	
				if(this.tabletype==2){
					this.isShared=0;
					this.sign=3
				}				
				this.getList();
			},
			'addtemplet.courseStage':function(){
				this.planselect=1;
				this.videoselect=1;
				this.drawselect=1;
				this.workselect=1;				
				this.getvideoList(1);
				this.getworkList(1);
				this.getdrawList(1);
				this.getplanList(1);	
				this.addtemplet.planIds=[];
				this.addtemplet.problemIds=[];
				this.addtemplet.drawingIds=[];
				this.addtemplet.videoIds=[];
			},
			'addtemplet.businessModelId':function(){
				this.planselect=1;
				this.videoselect=1;
				this.drawselect=1;
				this.workselect=1;		
				this.getvideoList(1);
				this.getworkList(1);
				this.getdrawList(1);
				this.getplanList(1);				
			},		
			'planselect':function(){
				if(this.planselect==1){
					this.planisShared='';
					this.planisSelf=1;
				}
				if(this.planselect==2){
					this.planisShared=1;
					this.planisSelf=2;
				}
				if(this.planselect==3){
					this.planisShared=0;
					this.planisSelf=3;					
				}	
				this.getplanList();							

			},
			'videoselect':function(){
				if(this.videoselect==1){
					this.videoisShared='';
					this.videoisSelf=1;
				}
				if(this.planselect==2){
					this.videoisShared=1;
					this.videoisSelf=2;
				}
				if(this.planselect==3){
					this.videoisShared=0;
					this.videoisSelf=3;					
				}	
				this.getvideoList();							

			},
			'workselect':function(){
				if(this.workselect==1){
					this.workisSelf=1;
					this.workisShared='';					
				}
				if(this.workselect==2){
					this.workisSelf=2;
					this.workisShared=1;					
				}
				if(this.workselect==3){
					this.workisSelf=3;
					this.workisShared=0;							
				}	
				this.getworkList();	
			},
			'drawselect':function(){
				if(this.drawselect==1){
					this.drawisSelf=1;
					this.drawisShared='';						
				}
				if(this.drawselect==2){
					this.drawisShared=1;
					this.drawisSelf=2;	
				}
				if(this.drawselect==3){
					this.drawisShared=0;
					this.drawisSelf=3;						
				}	
				this.getdrawList();							
			}			
		},
		methods: {	
		    sortChange:function(column, prop, order){
				if(column){
			      var type='';
			      if(column.prop=='createTime'){
			      	column.prop='create_time';
			      }else if(column.prop=='referenceCount'){
			      	column.prop='reference_count';
			      }
			      if(column.order=="ascending"){
			      	type=column.prop;	
			      }else if(column.order=='descending'){
			      	type=column.prop+' '+'desc';
			      }
			      this.getList(type)			 	
				}
		    },	
			Businessmodel:function(){
				this.planselect=1;
				this.videoselect=1;
				this.drawselect=1;
				this.workselect=1;		
				this.getvideoList(1);
				this.getworkList(1);
				this.getdrawList(1);
				this.getplanList(1);				
			},			    
			getvideoList: function (type) {
				if(this.templettype=='edit'){
					var courseStage=this.edittemplet.courseStage;
					if(courseStage==1){
						var businessModelId=null;
					}else{
						var businessModelId=this.edittemplet.businessModelId
					}
				}else{
					var courseStage=this.addtemplet.courseStage;
					if(courseStage==1){
						var businessModelId=null
					}else{
						var businessModelId=this.addtemplet.businessModelId
					}		
				}
				let params={pageSize:0,sign:this.videoisSelf,isShared:this.videoisShared,courseStage:courseStage,businessModelId:businessModelId};
				videolist(params).then((res) => {
					$.each(res.list, function(e,value) {
						value.videoId=JSON.stringify(value.videoId)
					});
					this.videolist = res.list;
				});	
			},
			getworkList: function (type) {
				if(this.templettype=='edit'){
					var courseStage=this.edittemplet.courseStage;
					if(courseStage==1){
						var businessModelId=null;
					}else{
						var businessModelId=this.edittemplet.businessModelId
					}
				}else{
					var courseStage=this.addtemplet.courseStage;
					if(courseStage==1){
						var businessModelId=null
					}else{
						var businessModelId=this.addtemplet.businessModelId
					}						
				}			
				let params={pageSize:0,sign:this.workisSelf,isShared:this.workisShared,courseStage:courseStage,businessModelId:businessModelId};
				worklist(params).then((res) => {
					$.each(res.list, function(e,value) {
						value.problemId=JSON.stringify(value.problemId)						
					});						
					this.worklist = res.list;
				});
			},		
			getdrawList: function (type) {
				if(this.templettype=='edit'){
					var courseStage=this.edittemplet.courseStage;
					if(courseStage==1){
						var businessModelId=null;
					}else{
						var businessModelId=this.edittemplet.businessModelId
					}
				}else{
					var courseStage=this.addtemplet.courseStage;
					if(courseStage==1){
						var businessModelId=null
					}else{
						var businessModelId=this.addtemplet.businessModelId
					}		
				}					
				let params={pageSize:0,sign:this.drawisSelf,isShared:this.drawisShared,courseStage:courseStage,businessModelId:businessModelId};
				drawlist(params).then((res) => {
					$.each(res.list, function(e,value) {
						value.drawingId=JSON.stringify(value.drawingId)						
					});						
					this.drawlist = res.list;
				});	
			},	
			getplanList: function (type) {
				if(this.templettype=='edit'){
					var courseStage=this.edittemplet.courseStage;
					if(courseStage==1){
						var businessModelId=null;
					}else{
						var businessModelId=this.edittemplet.businessModelId
					}
				}else{
					var courseStage=this.addtemplet.courseStage;
					if(courseStage==1){
						var businessModelId=null
					}else{
						var businessModelId=this.addtemplet.businessModelId
					}		
				}					
				let params={pageSize:0,sign:this.planisSelf,isShared:this.planisShared,courseStage:courseStage,businessModelId:businessModelId};
				planlist(params).then((res) => {
					$.each(res.list, function(e,value) {
						value.planId=JSON.stringify(value.planId)						
					});							
					this.planlist = res.list;
				});		
			},	
			getAllList:function(courseStage,businessModelId){
				var _this=this;
				_this.worklist=[];
				_this.drawlist=[];
				_this.videolist=[];
				_this.planlist=[];
				let selfparams={pageSize:0,sign:4,courseStage:courseStage};
				worklist(selfparams).then((res) => {
					$.each(res.list, function(e,value) {
						value.problemId=JSON.stringify(value.problemId)	
						_this.worklist.push(value)
					});
				});					
				drawlist(selfparams).then((res) => {
					$.each(res.list, function(e,value) {
						value.drawingId=JSON.stringify(value.drawingId)	
						_this.drawlist.push(value)
					});
				});			
				videolist(selfparams).then((res) => {
					$.each(res.list, function(e,value) {
						value.videoId=JSON.stringify(value.videoId)	
						_this.videolist.push(value)
					});
				});		
				planlist(selfparams).then((res) => {
					$.each(res.list, function(e,value) {
						value.planId=JSON.stringify(value.planId)	
						_this.planlist.push(value)
					});
				});		
			},
			goShared:function(row,type){
				this.$confirm('确定操作吗?', '提示', {
			        confirmButtonText: '确定',
			        cancelButtonText: '取消',					
					type: 'warning'
				}).then(() => {
					var params=new URLSearchParams();
					params.append('isShared',type);
					params.append('templetId',row.templetId);
					templetedit(params).then((r) => {
						if(!r.error){
							this.$message({
								message: '操作成功',
								type: 'success'
							});
							this.getList();									
						}else{
							this.$message({
								message: '操作失败',
								type: 'error'
							});						
						}
					})	
				})			
			
			},
			handleAdd: function () {
				this.addFormVisible = true;
				this.templettype='add';
				this.getvideoList(1);
				this.getworkList(1);
				this.getdrawList(1);
				this.getplanList(1);					
			},
			isSharedclick:function(type){
				this.isShared=type;
				this.getList();
			},
			//获取商业模式列表
			getbussinesslist:function(){
				bussinesslist().then((res)=>{
					$.each(res, function(i,value) {
						value.businessModelId=JSON.stringify(value.businessModelId)
					});
					this.bussinessList=res;
				})
			},	
			//获取项目列表
			getList: function (type) {
				this.loading = true;
				//NProgress.start();
				let params={pageNum:this.page,pageSize:this.pagesize,key:this.key,isShared:this.isShared,sign:this.sign,orderByClause:type};
				templetlist(params).then((res) => {
					this.total=res.total;		
					this.Lists = res.list;
					this.loading = false;
				});		
			},
			getone:function(row,type){
				var params=row.templetId+"?deep=1";
				this.templettype='edit';	
				if(row.courseStage!=1){
					this.edittemplet.businessModelId=JSON.stringify(row.businessModelId);
				}else{
					row.businessModelId=null;
				}
				this.edittemplet.courseStage=JSON.stringify(row.courseStage);				
				this.getAllList(this.edittemplet.courseStage);				
				templetone(params).then((res)=>{
					 var _this = this
					if(!res.error){
						if(res.drawingIds!=null){
							res.drawingIds=res.drawingIds.split(',');						
						}else{
							res.drawingIds=[]
						}
						if(res.problemIds!=null){
							res.problemIds=res.problemIds.split(',');				
						}else{
							res.problemIds=[]
						}
						if(res.planIds!=null){
							res.planIds=res.planIds.split(',');			
						}else{
							res.planIds=[]
						}	
						if(res.videoIds!=null){
							res.videoIds=res.videoIds.split(',');
						}else{
							res.videoIds=[]
						}		
						res.checkname=res.name;
						res.courseStage=JSON.stringify(res.courseStage);				
						res.businessModelId=JSON.stringify(res.businessModelId);						
						setTimeout(function(){
							_this.edittemplet = Object.assign({}, res);
						},200)
						if(type=='edit'){
							_this.editFormVisible=true;
						}else{
							_this.lookVisible=true;
						}	

					}
				})				
			},
			Lookone:function(row,type){
				var params=row.templetId+"?deep=2";
				templetone(params).then((res)=>{
					 var _this = this
					if(!res.error){
						res.courseStage=JSON.stringify(res.courseStage);	
						res.businessModelId=JSON.stringify(res.businessModelId);	
						_this.looktemplet = Object.assign({}, res);
						_this.lookVisible=true;
					}
				})				
			},			
			handleCurrentChange(val) {
				this.page = val;
				this.getList();
			},		            
			handleDel:function (row) {
				this.$confirm('确认删除该记录吗?', '提示', {
			        confirmButtonText: '确定',
			        cancelButtonText: '取消',					
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					let para =row.templetId;		
					templetdelete(para).then((res) => {
						if(!res.error){
							this.listLoading = false;
							//NProgress.done();
							this.$message({
								message: '删除成功',
								type: 'success'
							});
							this.getList();							
						}
					});
				})
			},
			//新增
			addSubmit: function () {		
				var _this=this;
				if(_this.addtemplet.planIds.length==0){
					_this.$message({
						message: '教案不能为空',
						type: 'error'
					});				
					return
				}
				if(_this.addtemplet.drawingIds.length==0&&this.addtemplet.courseStage==1){
					_this.$message({
						message: '图纸不能为空',
						type: 'error'
					});				
					return
				}
				if(_this.addtemplet.problemIds.length==0){
					_this.$message({
						message: '试题不能为空',
						type: 'error'
					});				
					return
				}				
				this.param=new URLSearchParams();
				this.$refs.addtemplet.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {
					        confirmButtonText: '确定',
					        cancelButtonText: '取消',					
							type: 'warning'								
						}).then(() => {
							this.addLoading = true;
							this.param.append('name',this.addtemplet.name);
							this.param.append('videoIds',this.addtemplet.videoIds);				
							this.param.append('problemIds',this.addtemplet.problemIds);
							this.param.append('drawingIds',this.addtemplet.drawingIds);
							this.param.append('planIds',this.addtemplet.planIds);
							this.param.append('courseStage',this.addtemplet.courseStage);
							if(this.addtemplet.courseStage==0){
								this.param.append('businessModelId',this.addtemplet.businessModelId);
							}
							templetadd(this.param).then((r) => {
								if(!r.error){
									this.addLoading = false;
									this.$message({
										message: '添加成功',
										type: 'success'
									});
									this.addFormVisible = false;
									this.param='';
									this.addtemplet={
										name:"",
										type:"",
										courseStage:"0",
										businessModelId:"",
										planIds:[],
										problemIds:[],
										videoIds:[],
										drawingIds:[],
									};								
									this.getList();									
								}else{
									this.addLoading = false;
									this.param='';
									this.$message({
										message: '添加失败',
										type: 'error'
									});										
								}
							}).catch(() => {
								this.addLoading = false;					
							});	
						});
					}
				});
			},
			//编辑
			editSubmit: function () {
				this.editparam=new URLSearchParams();	
				this.$refs.edittemplet.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
							this.editLoading = true;
							//NProgress.start();
							this.editparam.append('name',this.edittemplet.name);
							this.editparam.append('videoIds',this.edittemplet.videoIds);
							this.editparam.append('problemIds',this.edittemplet.problemIds);
							this.editparam.append('drawingIds',this.edittemplet.drawingIds);
							this.editparam.append('planIds',this.edittemplet.planIds);
							this.editparam.append('templetId',this.edittemplet.templetId);
							this.editparam.append('courseStage',this.edittemplet.courseStage);
							if(this.edittemplet.courseStage==0){
								this.editparam.append('businessModelId',this.edittemplet.businessModelId);
							}
							templetedit(this.editparam).then((r) => {
								if(!r.error){
									this.editLoading = false;
									this.$message({
										message: '更新成功',
										type: 'success'
									});
									this.editFormVisible = false;
									this.eidtparam='',
									this.getList();									
								}else{
								    this.editLoading = false;
									this.eidtparam='',
									this.$message({
										message: '更新失败',
										type: 'error'
									});											
								}
							})
						});
					}
				});
			},			
		},
		mounted() {

			this.getList()
			this.getbussinesslist()
		}
	};

</script>

<style>

.templetauto{
	display: none;
}
.lookdialog{
	width: 100%;
	top: 0!important;
}
</style>